﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using XiaoGang.Soft.XGWMS.COM;

namespace XiaoGang.Soft.XGWMS.DAL_SQL
{
    public class DAL_M010_BILL
    {
        /// <summary>
        /// <p><b>方法名称</b>GetSingleData</p>	
        /// <p><b>概要説明  :</b>取得特定货单上的特定商品信息</p>
        /// <p><b>作成者    :</b>万岗</p>	
        /// <p><b>作成日    :</b>2008/09/03</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>
        /// <param type="class" name="model">检索条件</param>
        /// <returns type = "ReturnValue">执行结果信息</returns>
        public ReturnValue GetSingleData(MODEL.MOD_M010_BILL model)
        {
            //SqlParameter[] parameters = {
            //        new SqlParameter("@BILL_ID", SqlDbType.Char,12),
            //        new SqlParameter("@GOODS_ID", SqlDbType.Char,12)};
            //parameters[0].Value = model.BILL_ID.Trim();
            //parameters[1].Value = model.GOODS_ID.Trim();
            //return XGWMS.DBUtility.SqlHelper.Query(DAL_SQL.DAL_M010_BILL_SQL.Get_Single_Data_SQL, parameters);
            SqlParameter[] parameters = {
					new SqlParameter("@BILL_ID", SqlDbType.Char,12)};
            parameters[0].Value = model.BILL_ID.Trim();
            return XGWMS.DBUtility.SqlHelper.Query(DAL_SQL.DAL_M010_BILL_SQL.Get_Single_Data_SQL, parameters);
        }

        /// <summary>
        /// <p><b>方法名称</b>InsertProcess</p>	
        /// <p><b>概要説明  :</b>货单信息的插入</p>
        /// <p><b>作成者    :</b>万岗</p>	
        /// <p><b>作成日    :</b>2008/09/03</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>
        /// <param type="class" name="model">货单信息</param>
        /// <returns type = "ReturnValue">执行结果信息</returns>
        public ReturnValue InsertProcess(MODEL.MOD_M010_BILL model)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@TRANS_STATE", SqlDbType.Char,1),
					new SqlParameter("@UPDATER_ID", SqlDbType.VarChar,12),
					new SqlParameter("@TERMINAL_CD", SqlDbType.VarChar,256),
					new SqlParameter("@BILL_ID", SqlDbType.Char,12),
					new SqlParameter("@IN_OUT", SqlDbType.Char,1),
					new SqlParameter("@BUSINESS_TIME", SqlDbType.Char,8),
					new SqlParameter("@MEMO", SqlDbType.VarChar,256),
                    new SqlParameter("@USER_NO", SqlDbType.VarChar,12),
                    new SqlParameter("@Preferential", SqlDbType.Money)};
            parameters[0].Value = model.TRANS_STATE;
            parameters[1].Value = model.UPDATER_ID;
            parameters[2].Value = model.TERMINAL_CD;
            parameters[3].Value = model.BILL_ID;
            parameters[4].Value = model.IN_OUT;
            parameters[5].Value = model.BUSINESS_TIME;
            parameters[6].Value = model.MEMO;
            parameters[7].Value = model.USER_NO;
            parameters[8].Value = model.Preferential;
            return XGWMS.DBUtility.SqlHelper.ExecuteSql(DAL_M010_BILL_SQL.Insert_BILL_SQL, parameters);
        }

        /// <summary>
        /// <p><b>方法名称</b>SearchProcess</p>	
        /// <p><b>概要説明  :</b>货单信息的查询</p>
        /// <p><b>作成者    :</b>万岗</p>	
        /// <p><b>作成日    :</b>2008/09/10</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>
        /// <param type="class" name="model">货单信息</param>
        /// <returns type = "ReturnValue">执行结果信息</returns>
        public ReturnValue SearchProcess(MODEL.MOD_M010_BILL model)
        {
            StringBuilder strSql = new StringBuilder();
            if (0 != model.BILL_ID.Trim().Length)
            {
                strSql.AppendFormat(" AND M010.BILL_ID =  '{0}'   {1}", model.BILL_ID,               (char)13);
            }
            if (model.IN_OUT.Trim().Length != 0)
            {
                strSql.AppendFormat(" AND M010.IN_OUT = '{0}'     {1}", model.IN_OUT, (char)13);
            }
            if (0 != model.BUSINESS_START_TIME.Trim().Length)
            {
                strSql.AppendFormat(" AND M010.BUSINESS_TIME >= '{0}'   {1}", model.BUSINESS_START_TIME, (char)13);
            }
            if (0 != model.BUSINESS_END_TIME.Trim().Length)
            {
                strSql.AppendFormat(" AND M010.BUSINESS_TIME <= '{0}'   {1}", model.BUSINESS_END_TIME, (char)13);
            }
            string SQL = DAL_M010_BILL_SQL.GetBillList_SQL.Replace("@@@", strSql.ToString());
            SQL += " ORDER BY BUSINESS_TIME Desc,BILL_ID Desc,IN_OUT ";

            return XGWMS.DBUtility.SqlHelper.Query(SQL);
        }
    }
}
